<?php
namespace Common;

class Page {

	private $m_metaTags = array();
	private $m_charset;

	/**
	 * Called when using new PageView();
	 * @param string $charset
	 **/
	public function __construct($charset = 'utf-8') {
		$this -> m_charset = $charset;
	}

	/**
	 * Adds a CSS stylesheet to the head of the document
	 * @param urlstring $href url to css file
	 **/
	public function AddStyleSheet($href) {
		//TODO: '/>' is not really valid for 'HTML 4.01 Transitional' so these tags are not ended
		$this -> m_metaTags[] = '<link rel="StyleSheet" href="$href" type="text/css"';
	}

	/**
	 * Builds meta and CSS tags as a HTML/XML string
	 *
	 * @param bool $isXML is the document an XML file and tags should be closed
	 * @return string
	 */
	private function BuildHeadTags($isXML) {
		$end = '>';
		if ($isXML) {
			$end = '/>';
		}
		$retValue = '';
		foreach ($this->m_metaTags as $tag) {
			$retValue .= $tag . '$end\n            ';
			// '\n            ' for readability
		}
		return $retValue;
	}

	/**
	 * Returns a HTML 4.01 Transitional page
	 * @param string $title
	 * @param string $body
	 * @return string
	 **/
	public function GetHTMLPage($title, $body, $loginform) {

		$head = $this -> BuildHeadTags(true);

		$register = '';
		$login = '';
		$database = new \Model\Database();
		$database -> Connect(new \Model\DBConfig());
		$lh = new \Model\LoginHandler($database);
		$lv = new \View\LoginView();
		$objectview = new \View\ObjectView();
		$objectarray = new \Model\ObjectArray();
		$objectCatalog = new \Model\ObjectHandler($database);
		$objects = $objectCatalog -> getAllObjects();
		$archive = $objectview -> showListOfObjects($objects, false);
		$search = '';
		
		$personal = null;
		$meta = '<h2>META</h2>
						<ul>
							<li><a href="?register">Bli Medlem</a></li>';
		if ($lh->IsLoggedIn() == true) {
			
			$meta .= '<li><a href="?newobject">Ny object</a></li>';
			$name = $_SESSION["username"];
			$personal .= " <li class='dropdown'>
                                <a href='#' class='dropdown-toggle' data-toggle='dropdown'>$name <b class='caret'></b></a>
                                <ul class='dropdown-menu'>
                                    <li><a href='#'>Mina auktioner</a></li>
                                    <li><a href='#'>Inställningar</a></li>
                                    <li><a href='#'>Something else here</a></li>
                                    <li class='divider'></li>
                                    <li class='nav-header'>Nav header</li>
                                    <li><a href='#'>Separated link</a></li>
                                    <li><a href='#'>One more separated link</a></li>
                                </ul>
                            </li>";
		}
		$meta .= "</ul>";
		
		
		$xhtml = "
     	<!DOCTYPE HTML SYSTEM>
		<!--[if lt IE 7]>      <html class='no-js lt-ie9 lt-ie8 lt-ie7'> <![endif]-->
		<!--[if IE 7]>         <html class='no-js lt-ie9 lt-ie8'> <![endif]-->
		<!--[if IE 8]>         <html class='no-js lt-ie9'> <![endif]-->
		<!--[if gt IE 8]><!--> <html class='no-js'> <!--<![endif]-->
		<head>
        $head
        <meta charset='$this->m_charset'>
        <meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'>
        <title>$title</title>
        <meta name='description' content=''>
        <meta name='viewport' content='width=device-width'>
	  	<meta name='apple-mobile-web-app-status-bar-style' content='white' />
        <link rel='stylesheet' href='css/bootstrap.min.css'>
        <style>
            body {
                padding-top: 60px;
                padding-bottom: 40px;
            }
        </style>
        <link rel='stylesheet' href='css/bootstrap-responsive.min.css'>
        <link rel='stylesheet' href='css/main.css'>

	    <link rel='icon'type='image/png' href='Css/images/favicon.ico'>
	    <link rel='apple-touch-icon' href='Css/images/iPhoneIcon_Big.png'/>
	    <link rel='apple-touch-startup-image' href='Css/images/startup.png'>
	    <script type='text/javascript' src='validation.js'></script>
	    <script type='text/javascript' src='script.js'></script>
        <script src='js/vendor/modernizr-2.6.2-respond-1.1.0.min.js'></script>
    </head>
    <body>
        <!--[if lt IE 7]>
            <p class='chromeframe'>You are using an <strong>outdated</strong> browser. Please <a href='http://browsehappy.com/'>upgrade your browser</a> or <a href='http://www.google.com/chromeframe/?redirect=true'>activate Google Chrome Frame</a> to improve your experience.</p>
        <![endif]-->

        <!-- This code is taken from http://twitter.github.com/bootstrap/examples/hero.html -->

        <div class='navbar navbar-inverse navbar-fixed-top'>
            <div class='navbar-inner'>
                <div class='container'>
                    <a class='btn btn-navbar' data-toggle='collapse' data-target='.nav-collapse'>
                        <span class='icon-bar'></span>
                        <span class='icon-bar'></span>
                        <span class='icon-bar'></span>
                    </a>
                    <a class='brand' href='#'>BjudNu</a>
                    <div class='nav-collapse collapse'>
                        <ul class='nav'>
                            <li class='active'><a href='#'>Hem</a></li>
                            <li><a href='#about'>Om</a></li>
                            <li><a href='#contact'>Kontakt</a></li>
                           $personal
                        </ul>
                        $loginform
                    </div><!--/.nav-collapse -->
                </div>
            </div>
        </div>

        <div class='container'>

			<div class='search'>
			$search
			
			</div>
            <!-- Main hero unit for a primary marketing message or call to action -->
            <div class='hero-unit'>
            
                <h1>Välkommen till BjudNu!</h1>
                <p>This is a template for a simple marketing or informational website. It includes a large callout called the hero unit and three supporting pieces of content. Use it as a starting point to create something more unique.</p>
                <p><a class='btn btn-primary btn-large' href='?register'>Bli medlem &raquo;</a></p>
            </div>
			$body
            <!-- Example row of columns 
            <div class='row'>
                <div class='span4'>
                    <h2>Heading</h2>
                    <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
                    <p><a class='btn' href='#'>View details &raquo;</a></p>
                </div>
                <div class='span4'>
                    <h2>Heading</h2>
                    <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
                    <p><a class='btn' href='#'>View details &raquo;</a></p>
               </div>
                <div class='span4'>
                    <h2>Heading</h2>
                    <p>Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.</p>
                    <p><a class='btn' href='#'>View details &raquo;</a></p>
                </div>
            </div>
			-->
            <hr>

            <footer>
                <p>&copy; Company 2012</p>
            </footer>

        </div> <!-- /container -->

        <script src='//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'></script>
        <script>window.jQuery || document.write('<script src='js/vendor/jquery-1.9.1.min.js'><\/script>')</script>

        <script src='js/vendor/bootstrap.min.js'></script>

        <script src='js/main.js'></script>
	
	    
	    </body>
	</html>";
		
		return $xhtml;
	}
}
	